Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

[terra-popup] Move focus to first interactable child if available. #1476

Closed
wants to merge 6 commits into from

Conversation

pranav300
Copy link
Contributor

Summary

This PR fixes focus issues in the bounded popup where the focus was first received on the close button instead of the first interactable field.

The fix will focus on an interactable field if it is present and is not disabled/hidden. Otherwise, if there is no interactable field it will focus on to the close button.

Part of #1299

Deployment Link

https://terra-framework-deployed-pr-#.herokuapp.com/

Testing

I have added WDIO tests to verify the change.

Additional Details

focus on first interactable child

Thank you for contributing to Terra.
@cerner/terra

@ryanthemanuel ryanthemanuel temporarily deployed to terra-framew-move-focus-quqn7m October 19, 2021 18:38 Inactive
@pranav300 pranav300 added the hacktoberfest-accepted http://hacktoberfest.digitalocean.com label Oct 19, 2021

const UpdatedChildren = children.map(child => React.cloneElement(child));
UpdatedChildren.every((child, index) => {
if ((['a', 'button', 'input', 'textarea', 'select', 'details'].includes(child.type) || Object.keys(child.props).includes('tabIndex')) && child.props.tabIndex !== '-1') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious...how did we determine that these are the types to check?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the first layer of children provided to the PopupContent component are being validated here. This logic is not taking their potential interactive content into account. If you were to wrap the inputs in the test component in another div, they would not be detected by this logic.

The 'tabbable' dependency would be helpful in determining which elements are available for receiving focus in this scenario, regardless of those components' depths in the child structure. However, you would have to manually focus the element when the popup opens rather than relying on the autoFocus attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here ad5c6e0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is an interactable item in the mainContent then that will have focus. otherwise, it will check for interactable items in the headerContent and the first interactable item will be focused there as well. Based on priority the last item to get focus when popup is opened will be the close button

@ryanthemanuel ryanthemanuel temporarily deployed to terra-framew-move-focus-quqn7m October 24, 2021 11:12 Inactive
@ryanthemanuel ryanthemanuel temporarily deployed to terra-framew-move-focus-quqn7m October 24, 2021 11:30 Inactive
@ryanthemanuel ryanthemanuel temporarily deployed to terra-framew-move-focus-quqn7m October 24, 2021 11:43 Inactive
@pranav300 pranav300 closed this Oct 27, 2021
@pranav300
Copy link
Contributor Author

The issue is being reassessed.

@pranav300 pranav300 deleted the move-focus-to-first-interactable-child branch October 27, 2021 06:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug-fix hacktoberfest-accepted http://hacktoberfest.digitalocean.com 📦 terra-popup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants